package com.zhuojy.equity.mall.admin.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.Accounts;
import com.zhuojy.equity.mall.admin.common.entity.bo.AccountsBO;
import com.zhuojy.equity.mall.admin.common.pojo.JsonResult;
import com.zhuojy.equity.mall.admin.dal.mapper.AccountsMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 资金账户
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AccountsService extends ServiceImpl<AccountsMapper, Accounts> {

    /**
     * 资金账户条查分页
     *
     * @param accounts
     * @param pageNum
     * @param pageSize
     * @return
     */
    public JsonResult findAccountsPagination(Accounts accounts, Integer pageNum, Integer pageSize) {
        Page<Accounts> page = new Page<>(pageNum, pageSize);
        IPage<Accounts> accountsIPage = this.baseMapper.findAccountsPagination(accounts, page);
        return JsonResult.success(accountsIPage.getRecords(), accountsIPage.getTotal());
    }



    /**
     * 资金账户状态停用
     *
     * @param id
     */
    public void updateStatusting(Integer id) {
        this.baseMapper.updateStatusting(id);
    }

    /**
     * 启用
     *
     * @param id
     */
    public void updateStatusqi(Integer id) {
        this.baseMapper.updateStatusqi(id);
    }

    /**
     * 资金账户动态下拉列表框
     * @return
     */
    public List<Accounts> findOptions() {
        return this.baseMapper.findOptions();
    }

    /**
     * 资金账户新增
     * @param accounts
     */
    public void addAccounts(Accounts accounts) {
        accounts.setCreateTime(new Date());
        accounts.setStatus("停用");
        accounts.setCurrentBalance(5000.11);
        this.baseMapper.insert(accounts);
    }

    /**
     * 资金账户回显
     * @param id
     * @return
     */
    public Accounts findAccountsById(Integer id) {
        return this.baseMapper.selectById(id);
    }

    /**
     * 资金账户修改
     * @param accounts
     */
    public void updateAccounts(Accounts accounts) {
        this.baseMapper.updateById(accounts);
    }

    /**
     * 修改为默认
     * @param id
     */
    public void updateDefault(Long id) {
        this.baseMapper.updateDefault(id);
        this.baseMapper.updateDefaultTow(id);
    }
}
